{% set title = 'Error Request Report' %}
{% extends "ereporter2/base.html" %}


{% block header %}
<style>
  h1 {
    margin-top: 10px;
    margin-bottom: 10px;
  }

  h3 {
    margin-bottom: 5px;
  }

  table.property_table {
    font-family: monospace;
    border-spacing: 0;
  }

  table.property_table tbody tr:nth-child(even) {
    background-color: #eeeeee;
  }

  table.property_table td {
    padding-left: 1em;
    padding-right: 1em;
  }

  table.property_table tbody tr:hover {
    background-color: #eeffee;
  }
</style>
{% endblock %}


{% block body %}
<h1>Request error report</h1>

<table class=property_table>
  <tbody>
    <tr>
      <td>Version</td>
      <td>{{request.version_id}}</td>
    </tr>
    <tr>
      <td>Host</td>
      <td>{{request.host}}</td>
    </tr>
    <tr>
      <td>Resource</td>
      <td>{{request.resource}}</td>
    </tr>
    <tr>
      <td>Method</td>
      <td>{{request.method}}</td>
    </tr>
    <tr>
      <td>User agent</td>
      <td>{{request.user_agent}}</td>
    </tr>
    <tr>
      <td>IP</td>
      <td>{{request.ip}}</td>
    </tr>
    <tr>
      <td>Nickname</td>
      <td>{{request.nickname or '--'}}</td>
    </tr>
    <tr>
      <td>HTTP version</td>
      <td>{{request.http_version}}</td>
    </tr>
    <tr>
      <td>Referrer</td>
      <td>{{request.referrer or '--'}}</td>
    </tr>
    <tr>
      <td>HTTP Status</td>
      <td>{{request.status}}</td>
    </tr>
    <tr>
      <td>Response size</td>
      <td>{{request.response_size}}</td>
    </tr>
    <tr>
      <td>Start time</td>
      <td>{{request.start_time|epochformat('%Y-%m-%d %H:%M:%S.%f')}}</td>
    </tr>
    <tr>
      <td>End time</td>
      <td>{{request.end_time|epochformat('%Y-%m-%d %H:%M:%S.%f')}}</td>
    </tr>
    <tr>
      <td>Cost</td>
      <td>
        {% if request.cost %}
          {{'%0.5f' % (request.cost*100)}}¢
        {% else %}
          &#8209;&#8209;
        {% endif %}
      </td>
    </tr>
    <tr>
      <td>Duration (secs)</td>
      <td>{{request.latency}}</td>
    </tr>
    <tr>
      <td>Pending (secs)</td>
      <td>{{request.pending_time}}</td>
    </tr>
    <tr>
      <td>Machine cycles</td>
      <td>{{request.mcycles}}</td>
    </tr>
    <tr>
      <td>API machine cycles</td>
      <td>{{request.api_mcycles or '--'}}</td>
    </tr>
    <tr>
      <td>Module</td>
      <td>{{request.module_id}}</td>
    </tr>
    <tr>
      <td>Task queue name</td>
      <td>{{request.task_queue_name or '--'}}</td>
    </tr>
    <tr>
      <td>Task name</td>
      <td>{{request.task_name or '--'}}</td>
    </tr>
    <tr>
      <td>Loading request</td>
      <td>{{request.was_loading_request}}</td>
    </tr>
    <tr>
      <td>Appengine version</td>
      <td>{{request.app_engine_release}}</td>
    </tr>
  </tbody>
</table>
{# app_id, combined, finished, instance_key, offset, replica_index #}

<p>
<a href=https://appengine.google.com/instances?app_id={{request.app_id}}>
  View instances</a>
<br>
<a href="https://appengine.google.com/logs?app_id={{request.app_id}}">
  View logs in AppEngine log viewer
</a>
<p>

{% macro level(l) %}
{% if l == 0 %}Debug{% elif l == 1 %}Info{% elif l == 2 %}Warning{% elif l == 3 %}Error{% else %}Critical{% endif %}
{% endmacro %}


<h3>Logs</h3>
{% for log in request.app_logs %}
<strong>{{level(log.level)}}</strong>:
  {{log.time|epochformat('%Y-%m-%d %H:%M:%S.%f')}}
<pre>{{log.message}}</pre><br>
{% endfor %}

{% endblock %}
